package com.example.shushiyunsst.fragment.main.home.child.new_sale.recycler.provider

import android.content.Context
import android.view.View
import com.example.library_common.adapter.multi.JssMultiItemViewHolder
import com.example.library_common.adapter.multi.JssNewMultipleAdapter
import com.example.library_common.album.view.grid_view.XGridLayout
import com.example.library_common.album.view.grid_view.adapter.CommAdapter
import com.example.library_common.album.view.grid_view.adapter.XQuickViewHolder
import com.example.shushiyunsst.R
import com.example.shushiyunsst.fragment.main.home.child.new_sale.recycler.bean.NewSaleMineEntity
import com.example.shushiyunsst.fragment.main.home.child.new_sale.recycler.bean.NewSaleMineWrapperEntity
import com.senon.modularapp.util.JssSpannableString

class NewSaleMineProvider(view: View?)
    : JssMultiItemViewHolder<NewSaleMineWrapperEntity>(view){

    private var mAdapter: CommAdapter<NewSaleMineEntity>? = null

    override fun getItemLayout(): Int {
        return R.layout.new_sale_mine_provider
    }

    override fun convert(context: Context, m: NewSaleMineWrapperEntity?) {
        super.convert(context, m)
        val mLineLayout: XGridLayout = findView22(R.id.mLineLayout)

        if (mAdapter == null) {
            mAdapter = object : CommAdapter<NewSaleMineEntity>(
                context,
                R.layout.new_sale_mine_item_provider
            ) {
                override fun convert(
                    holder: XQuickViewHolder,
                    item: NewSaleMineEntity,
                    position: Int
                ) {
                    val createTime = item.createTime
                    val content = item.contentDesc
                    val string = JssSpannableString(
                        context, "$content $createTime"
                    )
                        .first(content)
                        .textColor(R.color.text_color_6)
                        .size(14)
                        .first(createTime)
                        .textColor(R.color.PrimaryColor)
                        .size(10)
                    holder.setText(R.id.titleTemplate, string)
                }
            }
        }
        if (adapter is JssNewMultipleAdapter<*>) {
            mLineLayout.setAdapter(mAdapter, (adapter as JssNewMultipleAdapter<*>).lifecycle)
        }

        mAdapter?.clear()
        mAdapter?.addAll(m?.getData() as MutableList<NewSaleMineEntity>)
    }


}